package com.example.nacosconfig;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;

import javax.annotation.PostConstruct;

@SpringBootApplication
public class NacosconfigApplication {
    @Value("${server.port}")  //这个取值不需要getset方法
    private Integer port;
    public static Integer port1;
    @Autowired
    Environment environment;
    public static Environment environment1;

    @PostConstruct
    private void getEnvironment() {
        port1 = this.port;
        environment1 = environment;
    }

    public static void main(String[] args) {
        SpringApplication.run(NacosconfigApplication.class, args);
        String mainport = environment1.getProperty("server.port");
//        Map<String, String> getenv = System.getenv(); //也取不到
//        String property = System.getProperty("local.server.port"); //null
//        NacosApplication nacosApplication = new NacosApplication();
//        Integer port = nacosApplication.getPort();  //port取不到
        while (true) {
            System.out.println("运行中" + "bootstrap.properties.server.port=" + mainport);
        }
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

}
